package com.easywork.mystery.service;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.easywork.mystery.entity.Poetry;
import com.easywork.mystery.es.EsPoetry;
import com.easywork.mystery.repository.EsPoetryRepository;
import com.easywork.mystery.repository.PoetryRepository;

@Transactional
@Service
public class PoetryService {
	@Autowired
	private PoetryRepository poetryRepository;
	@Autowired
	private EsPoetryRepository esPoetryRepository;

	public PoetryRepository getPoetryRepository() {
		return poetryRepository;
	}
	
	// --导入
	public void initData() {
		List<Poetry> list = poetryRepository.findAll();
		for (Poetry poetry : list) {
			EsPoetry esPoetry = new EsPoetry();
			BeanUtils.copyProperties(poetry, esPoetry);
			System.out.println("成功导入: " + esPoetry.getTitle());
			esPoetryRepository.save(esPoetry);
		}
	}
}